﻿
using FairyGUI;

namespace GameMain.Scripts.UI.Framework
{
    public static class UIUtils
    {
        /// <summary>
        /// 返回隐式全局缩放
        /// </summary>
        /// <returns></returns>
        public static float GetFitScale()
        {
            float widthRate = (float)UnityEngine.Screen.width / UIMgr.StandardScreenWidth;
            float heightRate = (float)UnityEngine.Screen.height / UIMgr.StandardScreenHeight;
            return heightRate < widthRate ? heightRate : widthRate;
        }
        
        /// <summary>
        /// 返回的已经隐式全局缩放的条件下，想要沾满全屏的Scale
        /// </summary>
        /// <param name="originWidth">原始宽</param>
        /// <param name="originHeight">原始长</param>
        /// <returns></returns>
        public static float GetFullScreenScale(float originWidth, float originHeight)
        {
            var rootW = GRoot.inst.width;
            var rootH = GRoot.inst.height;
            if(originWidth >= rootW && originHeight >= rootH) 
                return 1;
            var scaleX = rootW / originWidth;
            var scaleY = rootH / originHeight;
            return scaleX > scaleY ? scaleX : scaleY;
        }

        /// <summary>
        /// 返回安全区的总宽度（逻辑宽度）
        /// </summary>
        /// <returns></returns>
        public static float GetSafeWidth()
        {
            int screenWidth = UnityEngine.Screen.width;
            if (screenWidth > 1920)
            {
                screenWidth = screenWidth > 2100 ? 1920 + UnityEngine.Screen.width - 2100 : 1920;
            }
            return (float) screenWidth / UIMgr.GlobalFitScale;
        }
    }
}

